from flask import Flask, jsonify
from flask_cors import CORS
from datetime import datetime
import pytz

app = Flask(__name__)
CORS(app)  # 允许跨域请求，方便前端测试

@app.route('/<path:path>', methods=['GET', 'POST', 'PUT', 'DELETE'])
def handle_request(path):
    """
    处理所有HTTP请求，返回当前时间。
    """
    try:
        # 获取当前时间（HKT时区）
        hkt = pytz.timezone('Asia/Hong_Kong')
        current_time = datetime.now(hkt).isoformat()
        return jsonify({"current_time": current_time}), 200
    except Exception as e:
        return jsonify({
            "status": "error",
            "message": str(e)
        }), 500

@app.route('/', methods=['GET', 'POST', 'PUT', 'DELETE'])
def handle_root():
    """
    处理根路径请求，返回当前时间。
    """
    return handle_request('')

if __name__ == '__main__':
    print("Starting test HTTP server on http://127.0.0.1:5001")
    app.run(host='127.0.0.1', port=5001, debug=True)